<?php

define ('CMS_CHARSET', ''); // Example: iso-8859-1, utf-8, ...

error_reporting(7);
$dname1 = dirname(__FILE__)."/database/";
$dname2 = $_SERVER["DOCUMENT_ROOT"]."/TDE_CMS/database/";

if (file_exists($dname1))
    define ('DATABASE_FOLDER', $dname1);
else if (file_exists($dname2))
    define ('DATABASE_FOLDER', $dname2);
else
    define ('DATABASE_FOLDER', './TDE_CMS/database/');


function TDE_CMS_LoadContent($contentId)
{
    $path = DATABASE_FOLDER."content_".base64_encode($contentId);
    if (!file_exists($path))
        echo "TDE_CMS Warning: The Content ID is not related to any content in the database, please check that there is a content with the ID '".$contentID."'";
    else
    {
        $file = file($path);
        echo base64_decode(trim($file[1]));
    }
}

function TDE_CMS_LoadTitle($contentId)
{
    $path = DATABASE_FOLDER."content_".base64_encode($contentId);
    if (!file_exists($path))
        echo "TDE_CMS Warning: The Content ID is not related to any content in the database, please check that there is a content with the ID '".$contentID."'";
    else
    {
        $file = file($path);
        echo base64_decode(trim($file[0]));
    }
}

if ($_GET["content_id"] != '')
{
    if (CMS_CHARSET != '')
        header ('Content-type: text/html; charset='.CMS_CHARSET.';');
    if ($_GET["action"] == 'get_tde_content')
        TDE_CMS_LoadContent($_GET["content_id"]);
    else if ($_GET["action"] == 'get_tde_title')
        TDE_CMS_LoadTitle($_GET["content_id"]);
}

?>